<?php




namespace App\Http\Controllers\Api\User;


use App\Http\Controllers\Api\BasicController;
use App\Http\Controllers\Api\Site\DataController;
use App\Models\SiteCode;
use App\Models\User;
use App\Models\UserFocus;
use App\Models\UserInfo;
use App\Models\Users\TalentApply;
use App\Models\Users\TalentInfo;
use App\Services\Sms;
use GatewayWorker\Lib\Gateway;
use Jiannei\Response\Laravel\Support\Facades\Response;

class TalentController extends BasicController
{



    /**
     * @api {post} /talent/apply 达人申请
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */
    public function apply()
    {
        $data = $this->data(['name', 'mobile','talent_id','age_limit', 'certificate']);
        $data['user_id'] = $this->uid();
        $apply_info=TalentApply::where(['user_id'=>$data['user_id'],'talent_id'=>$data['talent_id']])->first();
        if(empty($apply_info))  $result = TalentApply::create($data);
        return Response::success($result ?? []);
    }

    /**
     * @api {post} /talent/apply-info 达人申请
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */
    public function applyInfo()
    {
        $data['user_id'] = $this->uid();
        $apply_info=TalentApply::where(['user_id'=>$data['user_id']])->get();
        return Response::success($apply_info ?? []);
    }
    /**
     * @api {post} /talent/info 达人申请
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */
    public function info()
    {
        $info=TalentInfo::all();
        foreach ($info as $item){
            $apply=TalentApply::where(['user_id'=>$this->uid(),'talent_id'=>$item->id])->first();
            if(empty($apply)){
                $item->status=-1;
            }else{
                $item->status=$apply->status;
            }
        }
        return Response::success($info);
    }

}
